//
//  ViewController.swift
//  RotationViewDemo
//
//  Created by 冉彬 on 2023/7/16.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .black
        let v = TurntableView(frame: CGRect(x: 0, y: 100, width: self.view.bounds.width, height: self.view.bounds.width))
        v.customItemViewAction = { tableView, index in
            var item = tableView.dequeueReusableItem(identifier: "RBTurntableItem") as? RBTurntableItem
            if item == nil {
                item = RBTurntableItem(identifier: "RBTurntableItem", size: CGSize(width: 44, height: 44), anchorpoint: CGPoint(x: 22, y: 22))
                item?.layer.cornerRadius = 22
            }
            item?.backgroundColor = .red
            item?.subviews.forEach({$0.removeFromSuperview()})
            let btn = UIButton(frame: item!.bounds)
            btn.addAction(UIAction(handler: { _ in
                print("\(index)")
            }), for: .touchUpInside)
            btn.setBackgroundImage(UIImage(named: "planet\(index%4)"), for: .normal)
            item?.addSubview(btn)
            return item!
        }
        v.itemCount = 6
        v.radius = v.bounds.height/2 - 22
        v.reloadUI()
        self.view.addSubview(v)
        let imageW = v.frame.width - 160
        let imageH = v.frame.height - 160
        
        let imageView = UIImageView(frame: CGRect(x: v.frame
            .origin.x + v.frame.width - imageW/2, y: v.frame
            .origin.y + 80, width: imageW, height: imageH))
        imageView.image = UIImage(named: "planet3")
        self.view.addSubview(imageView)
        
    }


    
}



class RBTurntableItem: TurntableItem {
    
}
